/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package requestManager;

import app.MyCellRenderer;
import app.MyTable;
import entities.EmployeeShiftRequest;
import java.util.ArrayList;
import java.util.Vector;
import javax.swing.JCheckBox;
import javax.swing.SwingConstants;
import lib.multiSpanCellTable.AttributiveCellTableModel;
import lib.multiSpanCellTable.CellSpan;

/**
 *
 * @author yoshi
 */
public class RequestManagerDefault extends AbstractRequestManager {

    public RequestManagerDefault(long departmentId) {
        super(departmentId);
    }

    @Override
    protected void initModel() {
        this.getMyModel().initDefault();
    }

    @Override
    protected void initTable() {
        ArrayList<EmployeeShiftRequest> requests = this.getMyModel().getRequests();
        Vector vData = new Vector();
        Vector vRowf = null;
        Vector vRowt = null;
        Vector vDisabledRows7 = new Vector();
        Vector vDisabledRows8 = new Vector();
        Vector vHead = new Vector(9);
        vHead.add("id");
        vHead.add("Date");
        vHead.add("Shift");
        vHead.add("Info");
        vHead.add("Note");
        vHead.add("Receive");
        vHead.add("Approve");
        vHead.add("Disapprove");

        int count = 0;

        for (EmployeeShiftRequest request : requests) {
            vRowf = new Vector();
            vRowf.add(request.getId());
            vRowf.add(request.getFromSchedule().getDate());
            vRowf.add(request.getFromSchedule().getTimeSlot().getId());
            vRowf.add(request.getFromSchedule().getEmployee().toFormatString());
            vRowf.add(new ViewNoteButtonModel(request));
            vRowf.add(new GenerateButtonModel(request));
            vRowf.add(new ApproveButtonModel(request));
            vRowf.add(new DisapproveButtonModel(request));

            vRowt = new Vector();
            vRowt.add("");
            vRowt.add(request.getRequestDate());
            vRowt.add(request.getTimeslot().getId());
            if (request.getEmployee().getId() != 0) {
                vRowt.add(request.getEmployee().toFormatString());
            } else {
                vRowt.add("?");
            }

            vRowt.add("");
            vRowt.add("");
            vRowt.add("");
            vRowt.add("");

            vData.add(vRowf);
            vData.add(vRowt);

            count++;
        }

        AttributiveCellTableModel ml = new AttributiveCellTableModel(vData, vHead);
        final CellSpan cellAtt = (CellSpan) ml.getCellAttribute();
        table = new MyTable();
        table.setModel(ml);
        /* Merge cells */
        int rowCount = table.getRowCount();
        for (int i = 0; i < rowCount; i += 2) {
            cellAtt.combine(new int[]{i, i + 1}, new int[]{0});
            cellAtt.combine(new int[]{i, i + 1}, new int[]{4});
            cellAtt.combine(new int[]{i, i + 1}, new int[]{5});
            cellAtt.combine(new int[]{i, i + 1}, new int[]{6});
            cellAtt.combine(new int[]{i, i + 1}, new int[]{7});
        }
        /* Align center */
        table.getColumnModel().getColumn(0).setCellRenderer(new MyCellRenderer(SwingConstants.CENTER));
        table.getColumnModel().getColumn(1).setCellRenderer(new MyCellRenderer(SwingConstants.CENTER));
        table.getColumnModel().getColumn(2).setCellRenderer(new MyCellRenderer(SwingConstants.CENTER));
        table.getColumnModel().getColumn(6).setCellRenderer(new MyCellRenderer(SwingConstants.LEFT));
        table.makeButtonColumn(4, new ViewNoteButtonEditor(new JCheckBox(), this), new ViewNoteButtonRenderer());
        table.makeButtonColumn(5, new GenerateButtonEditor(new JCheckBox(), this), new GenerateButtonRenderer());
        table.makeButtonColumn(6, new ApproveButtonEditor(new JCheckBox(), this), new ApproveButtonRenderer());
        table.makeButtonColumn(7, new DisapproveButtonEditor(new JCheckBox(), this), new DisapproveButtonRenderer());
        table.makeItuneColumn(1);
        table.makeItuneColumn(2);
        table.makeItuneColumn(3);
        table.setCellSelectionEnabled(false);
        
        table.setColumnWidth(0, 35);
        table.setColumnWidth(1, 80);
        table.setColumnWidth(2, 35);
        table.setColumnWidth(4, 110);
        table.setColumnWidth(5, 110);
        table.setColumnWidth(6, 110);
        table.setColumnWidth(7, 110);
    }
}
